<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String id = (String)request.getAttribute("id");
	String type = (String)request.getAttribute("type");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>广告图片录入</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<jsp:include page="/page/head.jsp"></jsp:include>
<script type="text/javascript">
		var id = "<%=id%>";
		var type = "<%=type%>";
		//保存信息
		function save(){
			var description = escape(escape($('#description').val()));   //获取description值
			var merchantId = escape(escape($('#merchant').combobox('getValue')));    //获取parent值
			var imageUrl = escape(escape($('#imageUrl').val()));    	//获取imageUrl值
			var layerOrder = escape(escape($('#layerOrder').val()));	//获取layerOrder值
			
			if($('#fm').form('validate')){
				//做操作类型判断
				var urlPath;
				if(type == "add"){
					//add处理路径
					urlPath = path +"/advertisement/save.do?description="+description+"&merchantId="+merchantId+"&imageUrl="+imageUrl+"&layerOrder="+layerOrder;
				}else{
					//update处理
					urlPath = path +"/advertisement/save.do?description="+description+"&merchantId="+merchantId+"&imageUrl="+imageUrl+"&layerOrder="+layerOrder;
					urlPath += "&id="+id;
				}
				$.ajax({
					  url:urlPath,
					  success: function() {
						  window.location = path+"/advertisement/advertisementMgr.do";
					  }
					});
			}
		}
		

		function selectImage(){
			var w =(screen.width-300)/2;
			var h = (screen.height-60)/2;
			var ret = window.showModalDialog(path+"/page/common/image-upload.jsp",window,"dialogWidth:300px;dialogHeight:60px;dialogTop:"+h+"px;dialogLeft:"+w+"px;help:no;status:no;center:yes");
			if(ret != null){
				$('#image').attr('src',path+"/"+ret[0][0]);
				$('#imageUrl').attr('value',ret[0][0]);
			}
		}
		
		//撤销回退
		function callback(){
			window.location = path+"/advertisement/advertisementMgr.do";
		}
	</script>
	
</head>

<body>
	<div class="right">
		<h1>
			<b>广告图片录入</b><span><img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span>
		</h1>
		<div class="ri_main">
		
				<table width="100%" border="0" cellspacing="1" cellpadding="8"
					style="background: #d9d9d9;">
					<tr>
						<td align="right" bgcolor="#FFFFFF">所属商家</td>
						<td bgcolor="#FFFFFF" align="left" >
						<input  
								class="easyui-combobox" <c:if test="${type=='1'}">disabled="disabled"</c:if> name="language" name="merchant" id="merchant"
								url="organization/listParent.do?type=1" valueField="id"
								textField="name" panelHeight="auto" 
								value="${advertisement != null?advertisement.merchant.id:''}" 
								text="${advertisement != null?advertisement.merchant.name:''}"  />
						</td>
					</tr>
					<tr>
						<td align="right" bgcolor="#FFFFFF">图片描述</td>
						<td bgcolor="#FFFFFF"  align="left" width="35%" colspan="3"><label
							for="textfield"></label> 
						<input
							id="description" name="description" value="${advertisement != null?advertisement.description:''}" class="easyui-validatebox" required="true" style="width: 150px;">
						</td>
					</tr>
					<tr>
						<td align="right" bgcolor="#FFFFFF">广告图片</td>
						<td bgcolor="#FFFFFF" colspan="3">
						<img id="image" width="200" height="200" name="image" src="<%=basePath %>${advertisement != null?advertisement.imageUrl:''}"></img>
							<input type="hidden" id="imageUrl" name="imageUrl" value="${advertisement != null?advertisement.imageUrl:''}">
							<input type="button" onclick="selectImage()" value="选择" />
						</td>
					</tr>
					<tr>
						<td width="15%" align="right" bgcolor="#FFFFFF">同城排序</td>
						<td bgcolor="#FFFFFF"  align="left" width="35%" colspan="3"><label
							for="textfield"></label> 
						<input
							id="layerOrder" name="layerOrder" value="${advertisement != null?advertisement.layerOrder:''}" class="easyui-validatebox"  style="width: 150px;">
						</td>
					</tr>
					<tr>
						<td bgcolor="#FFFFFF" colspan="4" align="center">
						<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a> 
						<a href="javascript:void(0);" class="easyui-linkbutton"
							iconCls="icon-cancel" onclick="callback()">取消</a>
						</td>
					</tr>
					
				</table>
			
		</div>
	</div>
</body>
</html>
